<script setup lang="ts">
import CusCustomNavbar from '@/pages/index/components/CustomNavbar.vue'
import { onLoad } from '@dcloudio/uni-app'
import {
  getHomeBanner,
  getHomeCatagory,
  getGoodsListByHot,
  getGoodsListByNew,
  getGoodsListByRecommend,
} from '@/services/home'
import { ref } from 'vue'
import type { BannerItem, CategoryItem, goodsInfo, goodsInfoByHot } from '@/types/home'
import CategoryPanel from '@/pages/index/components/CategoryPanel.vue'
import HotPanel from '@/pages/index/components/HotPanel.vue'
// import XtxGuess from '@/components/XtxGuess.vue'
import type { ProGuessInstance } from '@/components/components'
import PageSki from './components/PageSki.vue'

const bannerList = ref<BannerItem[]>([])
const getHomeBannerData = async () => {
  const res = await getHomeBanner()
  // console.log(res.data)
  bannerList.value = res.data
}
const isLoad = ref(false)
onLoad(async () => {
  isLoad.value = true
  await Promise.all([
    getHomeBannerData(),
    getHomeCatagoryData(),
    getGoodsListByHotData(),
    // getGoodsListByNewData(),
  ])
  // getHomeBannerData()
  // getHomeCatagoryData()
  // getGoodsListByHotData()
  // getGoodsListByNewData()
  // getGoodsListByRecommendData()
  isLoad.value = false
})

const catagoryList = ref<CategoryItem[]>([])
const getHomeCatagoryData = async () => {
  const res = await getHomeCatagory()
  // console.log(res.data)
  catagoryList.value = res.data
}

// const hotVal = ref('新鲜好物')
const goodsListByHotList = ref<goodsInfoByHot[]>([])
const getGoodsListByHotData = async () => {
  const res = await getGoodsListByHot()
  // console.lvscode-file://vscode-app/d:/VisualStudioCode/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.htmlog(res.data)
  goodsListByHotList.value = res.data
}

// const newVal = ref('热点资讯')
// const goodsListByNewList = ref<goodsInfoByHot[]>([])
// const getGoodsListByNewData = async () => {
//   const res = await getGoodsListByNew()
//   console.log(res.data)
//   goodsListByNewList.value = res.data
// }

// const pageInfo = ref({
//   pageSize: 10,
//   pageNum: 1,
// })
// const goodsList = ref<goodsInfo[]>([])
// const getGoodsListByRecommendData = async () => {
//   const res = await getGoodsListByRecommend()
//   console.log(res.data)
//   goodsList.value = res.data.goodsList
// }
const isRefresh = ref(false)
const guessRef = ref<ProGuessInstance>()
const onLower = () => {
  guessRef.value?.getMore()
}
const refresh = async () => {
  isRefresh.value = true
  // await getHomeBannerData()
  // await getHomeCatagoryData()
  // await getGoodsListByHotData()
  // await getGoodsListByNewData()
  guessRef.value?.refresh()
  await Promise.all([
    getHomeBannerData(),
    getHomeCatagoryData(),
    getGoodsListByHotData(),
    // getGoodsListByNewData(),
    guessRef.value?.getMore(),
  ])
  isRefresh.value = false
}
</script>

<template>
  <CusCustomNavbar></CusCustomNavbar>
  <scroll-view
    refresher-enabled
    @refresherrefresh="refresh"
    @scrolltolower="onLower"
    :refresher-triggered="isRefresh"
    class="scrow"
    scroll-y
  >
    <PageSki v-if="isLoad"></PageSki>
    <template v-else>
      <ProSwiper :list="bannerList"></ProSwiper>
      <CategoryPanel :list="catagoryList"></CategoryPanel>
      <!-- <HotPanel :list="goodsListByHotList" :type="hotVal"></HotPanel> -->
      <HotPanel :list="goodsListByHotList"></HotPanel>
      <!-- <HotPanel :list="goodsListByNewList" :type="newVal"></HotPanel> -->
      <!-- <ProGoodsGuess></ProGoodsGuess> -->
      <!-- <XtxGuess></XtxGuess> -->
      <ProGuess ref="guessRef"></ProGuess>
    </template>
  </scroll-view>
</template>

<style lang="scss">
//
page {
  background-color: #f7f7f7;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.scrow {
  flex: 1;
}
</style>
